#!/bin/sh

# 06.10.2005 Volker Quetschke
# Test if infered makefile generation works.
# (issue 54938)

: ${DMAKEPROG:=dmake}
file1="mymakefile.mk"
file2="incfile.mk"
file3="incfiledepend"
tmpfiles="$file1 $file2 $file3"

trap '{ echo "trapped signal - removing temporary files" ; rm -rf $tmpfiles ; }' 1 2 3 15

# Remove files from prior failed run
rm -rf $tmpfiles

# Remember to quote variables in generated makefiles( $ -> \$ ).
cat > $file1 <<EOT
# Verify that makefile generation is finished when using it
SHELL*:=/bin/sh 
SHELLFLAGS*:=-ce

incfile.mk : incfiledepend
	+@echo AA:=123 > \$@

incfiledepend :
	+@sleep 1
	+@echo 1234 > \$@

.INCLUDE : incfile.mk

all :
	+@echo aa:\$(AA):bb 
EOT

output=`eval ${DMAKEPROG} -r -P2 -f $file1 all`
result=$?

# The space between aaa and bbb comes from the +=
if test "$output" != "aa:123:bb"; then
  echo "Wrong result"
  result=1
fi


test $result -eq 0 && echo "Success - Cleaning up" && rm -f ${tmpfiles}
test $result -ne 0 && echo "Failure!"
exit $result
